feat(NIC-stats): added NIC statistics in shared memory with FFI and RPC, new states for yaml#713
Open
feat(NIC-stats): added NIC statistics in shared memory with FFI and RPC, new states for yaml#713
Conversation
added 10 commits
April 30, 2026 11:06
There was a problem hiding this comment.
Pull request overview
This PR adds a “global” dataplane shared-memory region to publish NIC statistics as counters, wires those counters through the C agent API and Go FFI, and exposes them via a new gRPC RPC. It also extends the dataplane YAML config schema to include globalstats storage sizing and NIC stats update cadence.
Changes:
- Introduce a global (non-instance) dp/cp shared-memory config region and a background NIC stats thread that updates counters in shared memory.
- Unify worker counter registry/storage naming (
worker_counters→counters) and add a newyanet_get_nic_countersAPI + Go FFI wrapper. - Add
CountersService.NICgRPC endpoint and new YAML config sections (globalstats,updatetimes).
Reviewed changes
Copilot reviewed 17 out of 17 changed files in this pull request and generated 13 comments.
Show a summary per file
| File | Description |
|---|---|
| mock/mock.c | Update mock initialization to link the renamed counter registry field. |
| lib/dataplane/config/zone.h | Rename per-instance counter fields to counters / counter_storage. |
| lib/controlplane/agent/agent.c | Add shared-memory accessor for global dp_config and a NIC counters getter. |
| dataplane/worker.c | Switch worker counter registration/storage usage to the renamed fields. |
| dataplane/meson.build | Include new globalstat.c in dataplane build. |
| dataplane/main.c | Start dataplane “daemons” (NIC stats thread) from main. |
| dataplane/globalstat.h | Define NIC/global stats structs and daemon entrypoints. |
| dataplane/globalstat.c | Implement NIC stats polling and counter updates. |
| dataplane/dataplane.h | Add global dp/cp config pointers and global stats storage in dataplane struct; declare daemon starter. |
| dataplane/dataplane.c | Allocate global shared-memory region; init global counters/storage; create NIC stats thread. |
| dataplane/config.h | Add globalstat memory sizing and updatetimes config structs. |
| dataplane/config.c | Extend YAML state machine to parse globalstats/updatetimes. |
| controlplane/ynpb/counters.proto | Add NIC RPC and NICCounterRequest message. |
| controlplane/internal/gateway/counters_service.go | Implement NIC RPC handler using global shared-memory dp_config. |
| controlplane/ffi/shm.go | Add DPGlobalConfig() accessor and NICCounters() wrapper around new C API. |
| api/counter.h | Export yanet_get_nic_counters in the public C API. |
| api/agent.h | Export yanet_shm_global_dp_config in the public C API. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+73
to
+76
| struct dp_config * | ||
| yanet_shm_global_dp_config(struct yanet_shm *shm) { | ||
| return dp_config_nextk((struct dp_config *)shm, yanet_shm_instance_count(shm)); | ||
| } |
Comment on lines
+360
to
+371
| uint64_t dp_memory = config->globalstat.dp_memory; | ||
| uint64_t cp_memory = config->globalstat.cp_memory; | ||
|
|
||
| struct dp_config *dp_config = (struct dp_config *)storage; | ||
| dataplane->global_dp_config = dp_config; | ||
|
|
||
| block_allocator_init(&dp_config->block_allocator); | ||
| block_allocator_put_arena( | ||
| &dp_config->block_allocator, | ||
| storage + sizeof(struct dp_config), | ||
| dp_memory - sizeof(struct dp_config) | ||
| ); |
Comment on lines
+516
to
+520
| // TODO: delete | ||
| dataplane->globalstat.cp_memory = (1 << 30) / 2; | ||
| dataplane->globalstat.dp_memory = (1 << 30) / 2; | ||
| dataplane->updatetimes.nic_updatetime = 1; | ||
|
|
Comment on lines
493
to
501
| break; | ||
| case state_connection: | ||
| state = state_connections; | ||
| break; | ||
| case state_globalstat: | ||
| state = state_dataplane; | ||
| break; | ||
| default: | ||
| goto error; |
Comment on lines
+787
to
807
| int | ||
| dataplane_daemons_start(struct dataplane *dataplane, struct dataplane_config *config) { | ||
| pthread_t thread_id; | ||
| pthread_create(&thread_id, NULL, stat_thread, dataplane); | ||
|
|
||
| struct stat_thread_args { | ||
| struct dataplane *dataplane; | ||
| struct dataplane_config *config; | ||
| }; | ||
|
|
||
| struct stat_thread_args *args = malloc(sizeof(struct stat_thread_args)); | ||
| if (args == NULL) { | ||
| LOG(ERROR, "failed to allocate memory for stat_thread_args"); | ||
| return -1; | ||
| } | ||
|
|
||
| args->dataplane = dataplane; | ||
| args->config = config; | ||
|
|
||
| pthread_create(&thread_id, NULL, stat_nic_thread, args); | ||
|
|
||
| return 0; |
|
|
||
| message DeviceCountersRequest { string device = 1; } | ||
|
|
||
| message NICCounterRequest { string device = 1; } |
Comment on lines
+132
to
+138
| func (m *CountersService) NIC( | ||
| ctx context.Context, | ||
| request *ynpb.NICCounterRequest, | ||
| ) (*ynpb.CountersResponse, error) { | ||
| dpConfig := m.shm.DPGlobalConfig() | ||
| counterValues := dpConfig.NICCounters() | ||
|
|
Comment on lines
90
to
98
| LOG(INFO, "start dataplane"); | ||
| dataplane_start(&dataplane); | ||
|
|
||
| LOG(INFO, "start dataplane daemons"); | ||
| dataplane_daemons_start(&dataplane, config); | ||
|
|
||
| // FIXME: infinite sleep effectively | ||
| LOG(INFO, "wait dataplane"); | ||
| dataplane_stop(&dataplane); |
Comment on lines
+20
to
+38
| static int | ||
| counter_register_counter( | ||
| struct dp_config *dp_config, const char *name, uint64_t size | ||
| ) { | ||
| yanet_error *err = NULL; | ||
| uint64_t rc = counter_registry_register( | ||
| &dp_config->counters, name, size, &err | ||
| ); | ||
| if (rc == COUNTER_INVALID) { | ||
| LOG(ERROR, | ||
| "failed to register '%s' counter: %s", | ||
| name, | ||
| yanet_error_message(err)); | ||
| yanet_error_free(err); | ||
| return -1; | ||
| } | ||
|
|
||
| return rc; | ||
| } |
Comment on lines
+791
to
+805
| struct stat_thread_args { | ||
| struct dataplane *dataplane; | ||
| struct dataplane_config *config; | ||
| }; | ||
|
|
||
| struct stat_thread_args *args = malloc(sizeof(struct stat_thread_args)); | ||
| if (args == NULL) { | ||
| LOG(ERROR, "failed to allocate memory for stat_thread_args"); | ||
| return -1; | ||
| } | ||
|
|
||
| args->dataplane = dataplane; | ||
| args->config = config; | ||
|
|
||
| pthread_create(&thread_id, NULL, stat_nic_thread, args); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.